Jquery Ajax

  • What is ajax

    
                        <head>
                        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
                        </head>
                      
  • Implementation

    Include Jquery library

    
                        <head>
                        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
                        </head>
                      

    In html

    
                          <div id="ajax_container" ></div>
                          <button type="button" class="btn_click">Click</button>
                      

    in script

    
    
                      <script>
                          $(document).ready(function () {
                              $(".btn_click").click(function () {
                                  $.ajax({
                                      url: "geeks.txt",
                                      success: function (result) {
                                          $("#ajax_container").html(result);
                                      }
                                  });
                              });
                          });
                      </script>
    
                        

    handle error

    
    
                        $(document).ready(function () {
                            $(".btn_click").click(function () {
                                $.ajax({  
                                    url: "geeks.txt",
                                    success: function (result) {
                                        $("#ajax_container").html(result);
                                    },
                                    error: function (xhr, status, error) {
                                        console.log(error);
                                    }
                                });
                            });
                        });